#!/usr/bin/env nodejs
// https://github.com/jakubkulhan/hit-server-bench/blob/master/node/main.js
//
// http://localhost:5000/

var cluster = require('cluster');
var http = require('http');

process.argv[process.argv.length - 1]
var workerCount = parseInt(process.argv[process.argv.length - 1]);

var handler = function (req, res) {
  res.writeHead(200);
  return res.end("Hello, World");
}

if (!isNaN(workerCount)) {
    if (cluster.isMaster) {
        for (var i = 0; i < workerCount; i++) {
            cluster.fork();
        }

        cluster.on('exit', function(worker, code, signal) {
            console.log('worker ' + worker.process.pid + ' died');
        });
    } else {
        http.createServer(handler).listen(5000);
    }
}
else {
    http.createServer(handler).listen(5000);
}
